Here are the requested updates. I have kept the locking separate from the helper, because in frequency calculation result depends on both values. I can move locking to the helper too if necessary, but I thought it would be logically cleaner this way...