Fix the autogenerated metadata field counts (rebased onto develop)



This is the same as gh-425 but rebased onto develop.

----

Fixes the metadata count problems noticed by @hflynn in #421.