Changed classes to "new style" classes

added context managers to file I/Os,
and added PEP8 fixes.