start code cleanup/optimization of cosmos subsystem
wrap up cleanup / optimization of cosmos subsystem

  also various other fixes