added end_run checking #370