Simplify mad and add details to doc

Simplified code and a little increased performance. See also #97.