Fixed for proper threading.

Signed-off-by: Szendvics <eandr2@gmail.com>