Refactoring and expanded documentation