added safe_input exception handling function