Refactoring. Create internal function provideMethodsFactory and remove duplicated code.