TODO comments added to encourage unit testing
started refactoring location function