moved location logic into a factory