basically implemented hw2b