Refactor state delta calculation in `/sync` handler.