Adds a better error handling.