trying to fix index out of bounds exception