first working version of the rewrite.