Refactor and bugfix of tiles