Refactored the common code into base classes