Better variable names and source of oscillator algorithm credited in comments