Moved repeated code to a new method