Added better logging, and some comments.