works now in thread