Fixed the grid draw order by making it a utility function