fixes to noise_measurement to keep memory usage reasonable

also some cleanup