Changed from absolute to grid coordinates.

Grouped functions into main / utility.