Solidifying error handling for script editor, fixing leaks