Issue #8 : Improve main loop