add terminate method to replace destructor.