implemented optimize for lists