Just a note:  The code format is kind of inconsistent throughout the file.  Some places it follows the coding standard and other places it does not.