fixed solution for Problem 3