refactor new analysis code