prepared code for handling state updates from server