fixed code with teacher assistance