improved Cython impl.