Refectored code for tone control