Logic optimizing of main loop

Nitpicked the code when a sudden clarification hit me - we should use a
switch instead. same result with much less code while keeping
readability - maybe even slightly better.. Will stop looking at code and
start documenting now.