isolate some of the sate updating to function