Retrofitted get_num from the old code; it turns out to be necessary.