Restructuring code

Forgot to move over things from https://github.com/danking/secondary-analysis
which is now defunct