Cython implementation