can we factor out the common logic here as well