Updated "newdevice" function with comments.