Further improved python3 compatibility; fixed some tests.