Forked from Jingxin's original code, includes time delays and some other things. Most changes are tagged with "URI" in comments