Minor bugfixes, checking out some possible optimizations through Cython extensions.