Tidy up some of the map bugs code