Fixing errors in Windows

Should build fine in Windows (VS2008) and run, however seems to crash on
exit.
Not sure if the crash is related to my environment or not since it does
not crash in Linux.