Broke everything up into module files for easier mantinence. Also removed some debugging code that isn't appropriate for prod.