fixed an index out of range exception