Adding better error handling.