Code for ex3 ported