rewrite some examples and their tests to make code more clear and optimizable