Add output file and clean up API calls. Still needs a little bit more work