Created and improved Stability function