refactoring repeated code