Refactoring and documentation updated