code restructured for Visual Studio