fixed handling of errno code