add comments and simplify