misc fixes and rearrangments