fixed some logic issues