Apply PR #17 to master: Various code cleanup.