implemented part1. fixed bugs