updated code for q 1 and 2