Refactoring: remove duplicated code