Refactored tag_device and untag_device methods