finished code for all questions