Rewriting a function