Add a lot of comments and clean up the code.