Added exception handling in main loop, tested OK