Fixes to make code work under python3

I am not quite sure about the metaclass thingy @ line 86.