adding comments, simplifying some parts