make the static analyzer happy

and fix some subtle bug as well