fix some logical problems