Major cleanup + improved map search algorithm