Format and bug fixes for build_metadata function.