Attempt to fix index out of bounds exception