fixed termination bug