updated savedocs function