refactored grid.js