Refactor client-side GUI code for connecting to server to avoid use of boolean flag