refactored code to replace multiple arrays by Tile object