added device state class to extract out functionality into object as part of refactoring