Fix bugs in email reminders script