whole bunch of cleanups and perf improvements