locate: remove some code duplication