Misc. fixes and formatting clean-up

replacement PR for  #7917