Various refactoring, documentation changes