Refactoring and improving documentation