split out code from webtorrent project