Refactoring. Improved documentation.