Week4: finished implementation