Rewrite done enough to be functional