Refactor: remove code duplication