added terminate_instance function