moved the finally statement to the end of the function, fixed the errors.