a whole bunch of cleanup and fixes