Updated Windows Only Code

Code is cleaned up to make it easy to port across platforms.
Merged Upstream