Add assert() calls to ensure consistent handling of the empty flag