Fix build on Windows.
Refactor out some redundancies.