Fixed 'Is a directory' IOError, added test