Moved repeated code
moved repeated code