Add some comments and rename a few functions.