new API - add back error function; throw in new state change callback