split off some code into a separate 'analyze' file with tests