The averaging trick and finite generation of invariants