moving stability function to a separate file