Refactor to pull out test-specific (LRT or Wald) code and hopefully reduce mem usage