major cleanup and fixes to make container shutdown properly when asked to