Refactored the windows stuff to be a bit cleaner