fixed a bug in HW4.R