try to make code more thread save