move some code out of the try block