adding threading code - commented