Join threads correctly