rewriting based on 2 examples, add function