Fix a couple of real bugs and also some gcc 4.7 compatibility