Fixed bug inside waveform period detection - hopefully no more freezing