adding function with conditional