Windows port; haven't tested these changes on OSX