fixed wrong if/else logic