organize code and add comments