Add some try-catch blocks to prevent crashing on error