Moved an internal function to a base class to remove duplicate code