started refactoring to remove duplication