Re-added routing algorithm, plus a couple of fixes.