restructure js, add summarize function