refactored grid.rb