refactored to use DocumentManager etc