Major refactoring/bug fixes in oscillator. Seems to be working now