function rewrite