Actually, can't this just be a middleware?