synced with latest version of SGScript