check for failures properly with return code