remove duplication and other refactorings