Remove some minor code duplication and add a bit more compatibility with Windows