Added an optional completion handler when setting a new state, called when the resulting actions complete.