Fixed scripting API and various fixes