Fix error handling undefined values