Minor improvements and also catch IOError

Minor improvements and also catch IOError