fixed up tiling algorithm