Refactoring, updated documentation