Python 3 compat

Added some changes to support python 3.
Tests work fine in python 3.3 and python 2.7 on ubuntu 12.10