Some code clean up and more comments