Added average state detection