Completed Problem 5, could be a better solution