Some bug fixes and win32 support