Change code to be threadsafe

The previous version retrieved doubleValues twice which could have resulted in percentages over 100 for instance.