updated solution for problem 50