Add count_versions utility function