May need some more cleanup for Win32, but I'll leave that to someone who can actually test the changes.