Rework metadata class dependencies to avoid cyclical import errors
Add tests