some tweaking of the factory example