cleaned up the code and refactored map_controller, moving the SQL stuff into the models