Fixed return code check logic