Use Cython to improve performance