cleaned up the code and made runscript