Cleanups and simplifications to increase code clarity

This doesn't look correct :-(