Fixed bug on locate function