Sorry for the huge commit. Bug fixes, enhancements and design work.