Moved a lot of code into common base classes