move threading code and quadtature selection into separate functions