rewrite script to be simpler