Move fetch functionality to libfetch, and make fetch use libfetch