Not sure what I've done wrong...

Where exactly do you think I should use a MAX variable? Because where ever I need to restrict it, I just use imageWidth and ImageHeight because they are the dimensions of the array.
Is that what you mean, or am I not getting your point?