Completely changed the script, now uses multiple arrays and a function to operate