REFACTOR improved exception handling and error messages