handle rewrites