Huge code cleanups