Added functions to select diffs from database for given documents. Warning: nasty horrible code