started to add functionality for arbitrary number of threads