fix for index out of range