Refactor of device state service