refactored pattern matching in special_fn