Updated solution for Python 3 compliance