Finished hw2 implementation