slightly restructured script