modified code to make it compile on VC++