refactor: split out service creation from function