Factor out a base class + error handeling