Refactor grid.rb for testing