Refactor Location detection and testing