lots of work on code clean up and logging