fixed some logical problems