Implemented hw2 to spec