More optimizations. Added Cython code.