Refactor code to remove duplication

Create an abstract super class to handle the logic in the run method.

Change-Id: I8f4f1598d724cdbffa08235995f055f42674941a