hhau's solution for exercise3