added more comments, fixed some bugs
more comments