fitted to latest version of SGScript (critical fix)