Reimplement some functions in terms of the standard library.

Also, make some of them raise ValueError/IndexError instead of
returning None in case of indexing errors.
Update the documentation.