partially done with part2, need to handle some error and rework part1