Fixed several bugs and moved code around, fixed https downloading support, shaved off roughly 50 SLOC of duplicated code.