Refactored locate.js a bit