Fix of a few bugs as judged from manual source inspection

While trying to migrate ctraits to Python 3, I found a few lines of code that look fishy to me. I did not test if they indeed do any harm. Each commit corresponds to a single isolated suspected bug. Please review!