rewrote optional scripts with high-level functions