fix index out of range exeption