Cleaning up the getMetadata function