Create inactiveStates list constant
Use fill inactiveTaskStates list for stop detection
Fix sort order