refactored the code in order to be consistent with the google c++ style guide