refactoring: remove duplicated code