A few major code cleanups