Fixed bug where diff was not being recorded correctly.

Turns out the reason `diff' was coming back as an empty string every time was
because I had introduced `diff' in the body of a while loop and was accessing
it outside of the while loop. `diff''s scope disappeared outside the while
loop.