Fix the tiles packing function.