Added error handling and some code for the devices