Add some more middleware and re-organise

In the unlikely event anyone is using this sorry
for the disruption!