Removed trailing white space.
Python 3.x compatibility refactoring. Fixed doctests.