Adds better error handling.