Fix logic error when masking out first element.
Add lots of documentation.