Allow running doctest files
remove duplicated code
Pass on optionflags to doctest