Edge case bug with nextDoc
Code Cleanup