Added isset check for $device
Fixed a number of issues preventing the admin settings page from saving successfully