Changes to make it compatible with lower version of scipy