Extract duplicate code in one method