adding threading and looping