factored out common metadata parsing code