Count var in total number instead of re-calling the function