New solution for assignment 39