Refactoring commom code to supertype.
Merge pull request #141 from arthurbenemann/issue129

Refactoring commom code to supertype.