diff --git a/agent.sh b/agent.sh
index a264e01c5f18ad178cf9a87e870f323e44e3c4e6..2cd3f60f7985975881fdf5c77b904d1668dc84c4 100755
--- a/agent.sh
+++ b/agent.sh
@@ -50,8 +50,9 @@ function rotateLogFile()
 function checkUpdate()
 {
     updateLink="$(${CLIENT} --update)"
+    returnValue=$?
 
-    if test $? -eq 4; then
+    if test ${returnValue} -eq 4; then
         test -f "${TMPDIR}/SEED2-update.run" || rm -f ${TMPDIR}/SEED2-update.run
 
         tryWget ${updateLink} \
@@ -65,11 +66,11 @@ function checkUpdate()
 
         rm -f ${TMPDIR}/SEED2-update.run
 
-        # Return 4 only if this isn't the first execution of the agent
-        test "${FIRST_EXECUTION}" || return 4
+        # Return 0 if this is the first execution of the agent
+        test "${FIRST_EXECUTION}" && return 0
     fi
 
-    return 0
+    return ${returnValue}
 }
 
 #------------------------------------------------------------------------------
@@ -149,7 +150,7 @@ updateStatus=$?
 test "${FIRST_EXECUTION}" && echo "${REALVERSION}" > "${VERSIONFILE}"
 
 test ${updateStatus} -eq 4 && exit 0
-if test ${updateStatus} -eq 1; then
+if test ${updateStatus} -ne 0; then
     date +"%F %T - Error while updating agent."
     exit 3
 fi