Refactored solution 5 and simplified testing.