refactor grid