added more comments, may have done some other improvements