Moved common code into a base-class.

  This closes #7.