Various bug fixes and refactoring and doc updates