Improved stability

Added some try/catch to the code