piles of changes, presumably to make this work on windows