Code for problem set 2