add json output
start to get rid of file/url conflation
start to break up huge function
move handler out of main function
move handler out of main function
use XML instead of CSV
fix unbound var
remove debugging lines