rewrote the working of popscript, v2.0