refactoring and use factory instead of scope