not sure if this is an improvement? it's more or less the same as the array version
switch to globals (passing array names around is ugly). (maybe look into dicts sometime?) also, properly detect width/height from the input instead of hardcoding it