algo code review. fixed memleak