Fixed bugs found by Cython.