update stopping criterion handling introducing shouldTerminate function