make past months function more general