fix for index out of bounds issue