the base script I wrote almost 3 yrs ago