Python 3 compatibility enhanced