Refactoring location logic