moved guiflag check before state machine loop

Fixes #126