working only for 1 thread