Better error handling logic.