library and ScriptEngine cleanup

- closes #1889