complete hw4
refactor work4.r