Updated stability function.

Still doesn't quite work yet though.