Downoads fix

peer reviewed by peng
Move this whole function into DocService