added fixed c++ code and added cython implimentation from scipy