Speed up by 50%

Avoid processing every line in the file - only process those
lines we need to find a state change.