started a Cythonized version, approx. 8x faster