Various improvements, and clean-ups

Refer to the commit log for details.