Unify duplicated codes