Added some documentation, small changes.

Changed nomenclature to improve coherence.
Removed redundant asserts, improved efficiency.