Cleanup of middleware