Changes to support VS3.1 and some error fixes