bunch of cleanup and reordering