Improve return from setDocument