Extract document/ot logic out of web service