move some in main to function and use Synchronizing Threads