Cleanup in locate.cpp + some ideas on how to improve the quality of the code