Fixed many compile issues with gcc and microsoft compilers.