more windows port
merge with upstream master