Windows fixes

Rebased and fixed some stuff.  This passes most tests (something's still wrong with plugins).