lots of code cleanups