Added base class, cleaned up code