Added some comments, fixed redundant code