refactor grid stuff