Fixed improper IOError sometimes.

Better IOError support.  Streamlined functions, removed old imports.