Added AddOnTerminate function

Added and slightly optimized the AddOnTerminate function to Simba.