fixed some logic faults
fixed some logic faults