some modifications for WIN32 support :)