add a bunch of comments and clean up source