add code for ex3.