Fixed a stability issue
Merged stability changes from the python version