Fix threading bug and initializing bug