fixed some logic