fix bug in #854 for data structures with >2 elements

@yilongli please review