Refactored code to make transitioning into pitch detection easier.