COMPLETE REWRITE. several test failures