clean up source code and add comments