refactored and add metadata