Moved common code into helper class