Working code for HW1 p.2