Refactored grid.js