Refactoring of merging and moving tiles logic