fixes for win32 and cleanup