Remove extension function, move code into hooks

So the code only runs on requests which actually need it.

Change-Id: I057f6e93b60037da2b01b1775f841726d14017ba