Fixed Index out of range error