refactoring midpoint_example