made changes to move one time used variables into error catching if statement