Refactor out shared code into abstract class.