Fix bug that caused illegal result values.