diff --git a/check_lysrdiff b/check_lysrdiff
index d2eeaaf4c8360db021f37a18920581eb317724b0..9a2c49779028e087f55e14b7b2054b877e71577b 100755
--- a/check_lysrdiff
+++ b/check_lysrdiff
@@ -62,7 +62,16 @@ state=$statecache-$partno
 find $BASE/lysrdiff/state -type f \
 	-printf "%TY-%Tm-%Td %TH:%TM:%TS %P\n" \
       | sort > $statecache.$partno.$$
-  mv -f $statecache.$partno.$$ $state
+mv -f $statecache.$partno.$$ $state || {
+  echo UNKNOWN - mv failed
+  rm $statecache.$partno.$$
+  exit 3
+}
+rm -f $state-stale $state-active || {
+  echo UNKNOWN - rm failed
+  rm $state
+  exit 3
+}
 
 echo $staletime MARKER \
 | sort $state - \
@@ -90,6 +99,8 @@ then
 	  END { if (sz >= 200) printf ", others" } ' \
     |sed s'/, \([^,]*\)$/ and \1/'
   echo '. | activity='$ACTIVITY stale=$STALE failed=`grep -c -- '-fail$' $state`
+  rm $state $state-stale $state-active
+
   exit 2
 fi
 
@@ -103,14 +114,17 @@ then
 	  END { if (sz >= 200) printf ", others" } ' \
     |sed s'/, \([^,]*\)$/ and \1/'
   echo '. | activity='$ACTIVITY stale=$STALE failed=0
+  rm $state $state-stale $state-active
   exit 2
 fi
 
 if [ $ACTIVITY = 0 ]
 then
   echo -n 'WARNING - No activity. | activity='0 stale=$STALE failed=0
+  rm $state $state-stale $state-active
   exit 1
 fi
 
 echo 'OK - all ok. | activity='$ACTIVITY stale=0 failed=0
+rm $state $state-stale $state-active
 exit 0