fix bug in check_range