fix some logic errors