in reply to Scrapper outputing error -w

If you can, get out of the habit of relying on global variables in functions like that. It is a sure fire way to get confused about what is happening in your code.

In the debugger enter a session on your script and immediately do this:

b switch_properties r
When you get into the switch properties code step down until you hit the offending 'get' line and then do this:
p $device
What do you see?

Celebrate Intellectual Diversity