modified some functions in tilemap module to make it more Pythonic