code refractor, add script to collect history detail data, and add unit test