serious cython optimization