REFACTOR: Learning to Extract Theorems from Proofs