Fix metaclasses to work on python 2 and 3