Moved repeated code.