rewrite the function