Rewrote Solution 3; in pretty good shape