add some comments, clean up code some more