Fixed several silly bugs, allowing the script to run! Calculations and parameter values are meaningless but the structure works.