Fix tests

I added tests for python3 and fix some code. Please review