Determine if requested documents exist and if they do, whether they match requested revision number
When you have code that starts to look like this, it's a sign that you need to write more functions to abstract some things away. You might put the code inside the two for loops into its own function, for example.