Cleanup code to be more readable.

Remove a no longer in use function and add a few additional comments to
make helper functions more clear.