structure code and write legend