A fractional Gehring lemma, with applications to nonlocal equations