Code reorganization + Ctrl+C support for stopping execution