updated solution for problem 41