fixed bugs when tile size is not a power of 2