improve optimization for cython