Cleaned up GUI state machine, should fix #40.