The if and else branches seem similar, do you think they could be refactored into one method?