fix for index out of bound