fixing code to answer the problem