Fix error, wrap code in try-finally