Add comments and simplify some code.