improve solution for assignment 5