Added if...then...else logic