Final bugfixes and doctests