Code cleanup and improve part2