Adding full code for files described in steps 5 and 6.