some improvements and bug fixes, python 2 support