possible bugfix of unset errno, added debug log