refactor, reduce duplicated code