refactored document.rb a bit