Bug 1098512 - Code cleanup and refactoring.

Removed dead and redundant code.  Fixed names of functions to be more
clear.  Rearranged function placement to be more logical.