Rewritten code nearly complete