Simplify apply_to_func, improve test coverage