Clean up some code and fixed pre c++11 compatibility