Added comments and use Google C++ style to format some of the code.