Refactoring and documentation improvements