Tests were broken in Python 3. Also fixed a couple of bugs that showed up.