Refactored some location code