Added a suitable error handling in mainUi