Implemented homework solution.