changing function name to avoid inner and outer var collision, and make it clearer that it returns a function