windows-port fixes merged in by hand.. eww