Cleanup and comment code

After the changes, not a bad idea to cleanup some code, and this code
definitely needed it. Hopefully it will be a little easier to read now.

Change-Id: I8bd016f0d2df005cef74fff1315c5bf6466d5679