Fixed assignment 4. Improved solution.