Fixed potential index out of range exception