improve logic of generating map