fixed if/else logic