Added IOError exception handling.