Edit main loop

- Change if to do-while
- Use non-blocking statement for subsequent reads