Factor out repository management into a class