fixed code and test for Python3