Refactor: remove duplicated code