moving win32 specific code into a static lib so that it compiles only once, also some minor code tidying