Simplified the comparators by checking for TypeOf(k1) == TypeOf(k2) first.