These nested blocks and the logic (setting `$zip = $state1`, then `$zip = $state1` again) are kinda hard to follow. This should be simplified -- I think using two `elsif`s will suffice.