Cleanup unused variables and old middleware support r=adrian