separate metadata work into another function