Also, if the logging is needed, you might consider only logging the first time this function is called instead of every time.