added refactored solution for conditional statement