Revamp scripting API to simplify it