fixed compilation on Windows plus a few fixes and cleanups.