refactored service code to be a factory