Fixed issues in Python3 and improved tests