Added alexandre's patch for last_entry_at logic error