Fix if else logic