fixed infinite termination issue