CAT rewrite, seems to work, but slooooow