split code up and made use of a base class to remove code duplication