rewrite some code, start logging