Updated windows only code with cross platform code for portability across platforms.

Some other tiny fixes as well.