added hella comments to explain this crazy tilemap voodoo