Made some changes to help with threading bug