massive code cleanups