Reworked to compile under Visual Studio