Add checking if saving to database was successful and refactor DeviceData class