Clean up old middleware code, add new ones