Some code cleanups, untested