Reworked login and retrieve_device_id functions