Fix some memory leaks
Add a script engine