Here is the total rewrite