Script fixes

Fixes #578, #577