Separated out the logic and created a separate "class" for managing the map. Should allow much clearer code and observe separation of concerns.