Add some comments, modify the code a bit.