Fix assorted PEP issues, better port file handling