Fixed Python 3 incompatibility and simplified query.