fixed some issues with threads