fixed out index out of range error