Refactor the idea: calling f() once or many times