handle the case where a function returns another function which is called immediately + tests