Added try catch finally to deal with cleanup.