Some small optimizations with cython