Fixed doctests and Python 2/3 compatibility