Cleaning up and fixing some bugs in cython