Removed unnecessary early return
Flattened loops (only shift advances); removed special case for EOI
Refactored result construction