Rewrote analyze script to be more modular