clean some code and get logging working