refactored code for location input