Add metadata array to function to avoid code repetition