Lots of cleanup. Adding comments.