Rewrote Solution 4