Generalized to custom container length.