added handling of IOError