fixed some minor logic bugs