Refactor grid split code