Add some abstract base classes and clean up.

Fixes #34