Some significant refactoring and improvement to documentation