Added OnClose-Methods and General Shutdown Mechanism