Corrected and finalized markAsRead function