Change api so that it returns a function.