Made a few changes that generally reduced the length of the script. A couple more improvements can be made, since there still are a couple lines of code that are repeating quite often.