Small refactoring, more comments and doc changes