rewrite with functions