Fixed errors and warnings found by gcc. All tests pass with gcc on windows