refactoring the coordinate system to start from the upper left