added some stuff to make it work in python3