added a check to avoid starting multiple threads