resolved possible end_routine bugs