added unset($spwd) also in case of errors