Added fixes from @samhain13

Added fixes from @samhain13. Thanks! :)
Is now compatible to both Python2 and Python3.