added comments, fixed a unit test