Updated some of the code to C++11 and added comments