Cleaned up code. Split locate.cpp into different files for clarity.