Fixed ArrayList index out of bounds exception