A lot of code cleanups