complete project1, verified correctness