Moving grid related logic to its own file