fix tests and improve compatibility with python 3.x