Add more comments and fix bugs.