refactoring: removing repeated code