Rearranged blocks and removed redundant logic

Fixed a bug introduced in c711c3cb69b61f22035c547011bd29e716060952 that
broke modes altogether

Rearranged some logic to reduce filesize and improve performance, should
not affect how the logic behaves