refined version of old script