Fix bug: checking if data is out of range