More error checking in download, and allow downloading directly to output
stream, and fix dependencies.