Better implementation of nextDoc in nextDocument