Fixing out of bounds error in insertSortedKey