more general retrieve_months function