Refactor location parsing