implemented automatic termination based on change in cost