Fix tests and doctests

review by @szeiger