This makes use of early continue/return to keep rightward drift under control. (I also find it easier to read.)