code refactoring; added ddoc comments