moving semi-static variable to lexical scope of the used function.