:nitpick: the two branches feel like they could be pulled out into small methods.