made a single general map update function

also cleaned up code