Updated briefly to add some global (no pun intended) variables to address previous issues.
Now uses dynamic variables to look through each location.