Moved state update to separate process. Fixed compile errors.