refactor grid printing