Fixes state reversion glitch.

-Fixes a glitch in which certain control packets incorrectly caused a state reversion,
 as a left-over piece of the data buffer was incorrectly interpreted as the current state.

-Normalizes all "invalid beacon IDs" to the number 31, rather than the (equivalent) -1.