Added some error recovery code