Fixed a Python 3 compatibility problem.

There was a comparison between None and an integer somewhere; this
is not allowed in Python 3. Corrected by checking for a None value
first.