Fixed a bug in the set_device method.