adding defensive coding, execution containment, minor bugfix (import os), improved test script