Code refactoring and documentation