clean up some code

Remove orphaned variables, add some comments
more cleanup