Fix some pointer related resource leaks in test files.
Refactor MC and FTA code that assigns indexes to primary events.