Finish functions, add doctests