Fixed return code checking