Better thread assignment algorithm for the quantity-balance method.
Updated the tests.