Ported to python 3.3. Minor bugfixes.