finished hw4. Need some testing.