did some clean up and wrote some comments