refactoring. removing duplication