core rewrite, still slow