fix valid range check