Improve cython performance