moving some declarations to fix scope issues when exceptions are caught