port to win32 and cleanup