Won't you need to check that behaviorCfg.activeBehaviorsCount is not overflowing ?