Add tests and fix circular dependency