optimised grid.js