added exception handling for IO errors