Extract duplicate code into own method.