fixed some logic faults