Refactored osc code