updated to optimize thread behaviour