Fixed possible out-of-range panic