Extract some redundant logic