Updated ordering and added another length check.