Unify duplicated code.