adding comments, code optimizing