refactor code related to Document