refactoring and more serious changes to the device id implementation