Refactored some repeated code

I introduced some repeated code, so i've condensed and refactored it into it's own method.

Refs #8031