fix error on first insert
simplify scripting api