Bug fix on checkValue function