implementation of thread worker