a lot of fixes. the script is now functional!