Abstracted #1383 & added tests.

Expands on the work done in #1383, applies it to all the metadata functions (including the one that was hardcoded regardless of the params passed in) & added tests for the new private function.