Quite a few bug fixes, improvements, code cleanups, and documentation