Issues with refactoring factory