Addes try-catch to recover from script errors