reworked threads synchronization