modified locate function