refactoring and simple test for metadata service