Added sine wave generation function, and unit tests for cycles.
Clarified comments on how several things work, reorganize a bit.