Code Cleanup

Miscellaneous minor functionality fixes, comment additions, and
"refactoring" to make code slightly more readable.