handle length = 0 and undefined better for cancels