also allow overriding the role metaclass (fixes #14)

also a bit of refactoring