Separate grid related code into a new file