add comments and a little code formatting