refactored apply_condition method