Added some comments and fixed a little bug