Better getTiles algorithm