simplify logic to avoid code duplication