more cleanups and rewrites