more cleanups and rewrites
merge