improved sine wave generation code