adapted script to work with environments