Add more commentary, and generalize some function names.