Refactor the code a bit to make it more readable and clean.

Authored by mwolff on Sep 6 2016, 11:56 AM.